import '../config/application.dart';
import '../public.dart';
import './dialog/confirmDailog.dart';
import './dialog/popRoute.dart';
import 'dialog/botton_input_dialog.dart';
import 'package:fluttertoast/fluttertoast.dart';

class Toast {
  static show(String msg) {
    Fluttertoast.showToast(
      msg: msg,
      gravity: ToastGravity.CENTER,
      fontSize: 12,
    );
  }

  static dailog(
      {
      /// 内容
      String content = '提示',

      /// 确认按钮文案
      String confirmText = '确认',

      /// 取消按钮文案
      String cancelText = '取消',

      /// 确定
      Function? confirm,

      /// 取消
      Function? cancel,

      /// 展示取消按钮
      bool showCancel = true,

      /// 点击背景可关闭
      bool barrierDismissible = true}) {
    showDialog(
        context: Application.navigateService.key.currentContext as BuildContext,
        barrierDismissible: barrierDismissible,
        builder: (_context) {
          return ConfirmDailog(
              message: content,
              cancelText: cancelText,
              confirmText: confirmText,
              showCancel: showCancel,
              onCancel: () {
                Navigator.of(_context).pop();
                if (cancel != null) cancel();
              },
              onConfirm: () {
                Navigator.of(_context).pop();
                if (confirm != null) confirm();
              });
        });
  }

  static inputDailog({
    String title = '内容',
    required TextEditingController textEditingController,
    TextInputType type = TextInputType.text,
    required Function(String) confirm,
    int? maxLength,
  }) {
    RouterHelper.navigator.push(
      PopRoute(
        child: BottomInputDialog(
          textEditingController: textEditingController,
          maxLength: maxLength,
          title: title,
          type: type,
          confirm: confirm,
        ),
      ),
    );
  }
}
